package com.kkb.kkbcommon.annotation.validation.validator;

import com.kkb.kkbcommon.annotation.validation.annotation.LandlineNumber;
import com.kkb.kkbcommon.basic.*;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @Author: 朱明亮
 * @Description: 座机号码校验器
 * @Data Created in 2021-08-20 15:00:30
 * @Modified by:
 */
public class LandlineNumberValidator implements ConstraintValidator<LandlineNumber, String> {
    @Override
    public void initialize(LandlineNumber constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return BaseUtil.haveEmpty(value) ? true : RegexUtil.isMatchByRegex(value, "^(0\\d{2,3})-?(\\d{7,8})$");
    }
}
